namespace jsWrite {
    interface ICalc {
        calc(arg0: number, arg1: number): number
    }
    
    class Agent1 implements ICalc {
        calc(arg0: number, arg1: number): number {
            return arg0 + arg1
        }
    }
    
    class Agent2 implements ICalc {
        calc(arg0: number, arg1: number): number {
            return Math.abs(arg0 - arg1)
        }
    }
    
    class use {
        delegate: ICalc;
        constructor(instance: ICalc){
            this.delegate = instance;
        }
        GetNum(num1:number,num2:number){
            return this.delegate.calc(num1,num2);
        }
    }
    
    //设置代理
    let person = new use(new Agent2());
    
    console.log(person.GetNum(1,2));
}